package com.sixth.volunteerservicesystem.Controller.ExamController.frontExam;

import com.sixth.volunteerservicesystem.Dao.QuestionRepository;
import com.sixth.volunteerservicesystem.Dao.TestPaperRepository;
import com.sixth.volunteerservicesystem.domain.TestPaper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * @author Steve Jobs
 * @create 2020-12-16 17:24
 */
@Controller
public class FinishExam {

    @Autowired
    QuestionRepository questionRepository;

    @Autowired
    TestPaperRepository testPaperRepository;

    @PostMapping("/exam/finishExam")
    public String  finish(
                         @RequestParam("1") String answer1,
                         @RequestParam("2") String answer2,
                         @RequestParam("3") String answer3,
                         @RequestParam("4") String answer4,
                         @RequestParam("5") String answer5,
                         @RequestParam("6") String answer6,
                         @RequestParam("7") String answer7,
                         @RequestParam("8") String answer8,
                         @RequestParam("9") String answer9,
                         @RequestParam("10") String answer10,
                         @RequestParam("11") String answer11,
                         @RequestParam("12") String answer12,
                         @RequestParam("13") String answer13,
                         @RequestParam("14") String answer14,
                         @RequestParam("15") String answer15,
                         @RequestParam("16") String answer16,
                         @RequestParam("17") String answer17,
                         @RequestParam("18") String answer18,
                         @RequestParam("19") String answer19,
                         @RequestParam("20") String answer20,
                         Model model
                         ){

        Integer score = 0;

        if(answer1.equals("true")){
            score += 5;
        }
        if(answer2.equals("true")){
            score += 5;
        }
        if(answer3.equals("true")){
            score += 5;
        }
        if(answer4.equals("true")){
            score += 5;
        }
        if(answer5.equals("true")){
            score += 5;
        }
        if(answer6.equals("true")){
            score += 5;
        }
        if(answer7.equals("true")){
            score += 5;
        }
        if(answer8.equals("true")){
            score += 5;
        }
        if(answer9.equals("true")){
            score += 5;
        }
        if(answer10.equals("true")){
            score += 5;
        }
        if(answer11.equals("true")){
            score += 5;
        }
        if(answer12.equals("true")){
            score += 5;
        }
        if(answer13.equals("true")){
            score += 5;
        }
        if(answer14.equals("true")){
            score += 5;
        }
        if(answer15.equals("true")){
            score += 5;
        }
        if(answer16.equals("true")){
            score += 5;
        }
        if(answer17.equals("true")){
            score += 5;
        }
        if(answer18.equals("true")){
            score += 5;
        }
        if(answer19.equals("true")){
            score += 5;
        }
        if(answer20.equals("true")){
            score += 5;
        }

        TestPaper testPaper = new TestPaper();
        testPaper.setScore(score);

        testPaper.setUserId("syd");

        testPaperRepository.save(testPaper);


        model.addAttribute("score",score);

        return "exam/finishExam";

    }
}
